package com.lonwin.mes2u8.domain.u8;

import com.google.common.collect.Lists;
import com.lonwin.mes2u8.common.CommonValue;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

@Data
public class U8ProductionHandlerResult {
    private String batchCode;
    private List<U8ProductionHandlerResultInfo> infoList;

    public U8ProductionAddParam convertU8ProductionAddParam() {
        List<U8ProductionAddParamInfoEntry> entries = Lists.newArrayList();
        for (U8ProductionHandlerResultInfo u8ProductionHandlerResultInfo : infoList) {
            if (Objects.isNull(u8ProductionHandlerResultInfo) || Objects.isNull(u8ProductionHandlerResultInfo.getInventorycode())
                    || StringUtils.isBlank(u8ProductionHandlerResultInfo.getInventorycode())
                    || Objects.isNull(u8ProductionHandlerResultInfo.getQuantity())
                    || u8ProductionHandlerResultInfo.getQuantity().compareTo(BigDecimal.ZERO) <= 0) {
                continue;
            }
            entries.add(u8ProductionHandlerResultInfo.convertProductionHandlerResultInfoEntry());
        }

        return U8ProductionAddParam.builder()
                .productin(
                        U8ProductionAddParamInfo.builder()
                                .maker(CommonValue.U8_PRODUCTION_MAKER)
                                .warehousecode("11").receivecode("105").departmentcode("03")
                                .memory(getBatchCode())
                                .entry(entries)
                                .build()
                )
                .build();
    }
}
